//
//  BQMyViewController.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/4/26.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQMyViewController.h"
#import "BQMineHeaderView.h"
#import "BQMineModel.h"
#import "BQAdressVC.h"
@interface BQMyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *mineTabelView;

@end

static NSString *Mine_Cell = @"Mine_Cell";

@implementation BQMyViewController{
    
    NSArray *_dataArray;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
}


-(void)viewWillAppear:(BOOL)animated

{
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
    
    [super viewWillAppear:animated];
    
    
    
}

-(void)setupUI{
    
    UITableView *mineTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, -22, _ScreenWidth, _ScreenHeight) style:UITableViewStyleGrouped];
    
    _mineTabelView = mineTabelView;
    
    mineTabelView.delegate = self;
    
    mineTabelView.dataSource = self;
    
    [self.view addSubview:mineTabelView];
    
    [mineTabelView registerClass:[UITableViewCell class] forCellReuseIdentifier:Mine_Cell];
    
    [mineTabelView setTableHeaderView:[BQMineHeaderView new]];
    
    

    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 1) {
        return 1;
    }
    
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Mine_Cell forIndexPath:indexPath];
    
    
    if (indexPath.section == 0) {
        BQMineModel *model = _dataArray[indexPath.row];
        
        cell.textLabel.text = model.title;
        
        cell.imageView.image = [UIImage imageNamed:model.iconName];
        
        return cell;
    }
    
    if (indexPath.section == 1) {
        BQMineModel *model = _dataArray[indexPath.row + 2];
        
        cell.textLabel.text = model.title;
        
        cell.imageView.image = [UIImage imageNamed:model.iconName];
        
        return cell;
    }
    BQMineModel *model = _dataArray[indexPath.row + 3];
    
    cell.textLabel.text = model.title;
    
    cell.imageView.image = [UIImage imageNamed:model.iconName];
   
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    //消除cell选择痕迹
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
    
    
    if(indexPath.section == 0 && indexPath.row == 0){
        
        
        [self.navigationController pushViewController:[[BQAdressVC alloc]init] animated:YES];
        
    }
    

}
- (void)deselect
{
    [self.mineTabelView deselectRowAtIndexPath:[self.mineTabelView indexPathForSelectedRow] animated:YES];
}

-(void)loadData{
    
    NSDictionary *para = @{@"call" : @3};
    
    [_AccountMgr POSTWithUrlString:mine_url parameters:para success:^(id responseObject) {
        
        // 获取分类模型数组
        NSArray *dictArray = responseObject[@"focus"];
        
        _dataArray = [NSArray yy_modelArrayWithClass:[BQMineModel class] json:dictArray];
        
        [self.mineTabelView reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;//section头部高度
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

@end
